package com.xiashitech.agent.instrumentation.base.propagator;

import com.xiashitech.agent.instrumentation.base.context.XSContext;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.context.propagation.TextMapGetter;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.context.propagation.TextMapSetter;

import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;

public class NoopReentryTextMapPropagator implements ReentryTextMapPropagator {
    private static final NoopReentryTextMapPropagator INSTANCE = new NoopReentryTextMapPropagator();

    static NoopReentryTextMapPropagator getInstance() {
        return INSTANCE;
    }

    @Override
    public Collection<String> fields() {
        return Collections.emptyList();
    }

    @Override
    public <C> void inject(XSContext context, @Nullable C carrier, TextMapSetter<C> setter) {}

    @Override
    public <C> XSContext extract(XSContext context, @Nullable C carrier, TextMapGetter<C> getter) {
        if (context == null) {
            return XSContext.root();
        }
        return context;
    }
}
